package com.synway.controller;

import com.synway.handler.SpiderHandler;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

@RestController
public class HouseController {
    @Autowired
    private AmqpTemplate rabbitTemplate;
    @Value("${python.rootPath}")
    private String rootPath;
    @Value("${python.env}")
    private String pythonEnv;

    @RequestMapping("/testloupan")
    public void testloupan(){
        SpiderHandler.rabbitTemplate =rabbitTemplate;
        SpiderHandler.spiderHandler(rootPath,pythonEnv,"loupan.py");
    }

    @RequestMapping("/testershou")
    public void testershou(){
        SpiderHandler.rabbitTemplate =rabbitTemplate;
        SpiderHandler.spiderHandler(rootPath,pythonEnv,"ershou.py");
    }

    @RequestMapping("/testzufang")
    public void testzufang(){
        SpiderHandler.rabbitTemplate =rabbitTemplate;
        SpiderHandler.spiderHandler(rootPath,pythonEnv,"zufang.py");
    }

    @RequestMapping("/testxiaoqu")
    public void testxiaoqu(){
        SpiderHandler.rabbitTemplate =rabbitTemplate;
        SpiderHandler.spiderHandler(rootPath,pythonEnv,"xiaoqu.py");
    }

    @RequestMapping("/testloupantodb")
    public void testloupantodb(){
        SpiderHandler.spiderHandler(rootPath,pythonEnv,"loupan_to_db.py");
        SpiderHandler.rabbitTemplate = rabbitTemplate;
    }

    @RequestMapping("/testershoutodb")
    public void testershoutodb(){
        SpiderHandler.rabbitTemplate =rabbitTemplate;
        SpiderHandler.spiderHandler(rootPath,pythonEnv,"ershou_to_db.py");
    }

    @RequestMapping("/testxiaoqutodb")
    public void testxiaoqutodb(){
        SpiderHandler.rabbitTemplate =rabbitTemplate;
        SpiderHandler.spiderHandler(rootPath,pythonEnv,"xiaoqu_to_db.py");
    }

    @RequestMapping("/testzufangtodb")
    public void testzufangtodb(){
        SpiderHandler.rabbitTemplate =rabbitTemplate;
        SpiderHandler.spiderHandler(rootPath,pythonEnv,"zufang.py");
    }

    @GetMapping("/test2")
    public void test2(){
        rabbitTemplate.convertAndSend("SPIDER_QUEUE","loupan.py".split("\\.")[0]);
    }

}
